package com.lagou.homework.module;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Word implements WritableComparable<Word> {

    private int rank;
    private int word;

    @Override
    public int compareTo(Word o) {
        return Integer.compare(this.word, o.word);
    }

    @Override
    public void write(DataOutput output) throws IOException {
        output.writeInt(rank);
        output.writeInt(word);

    }

    @Override
    public void readFields(DataInput input) throws IOException {
        this.rank = input.readInt();
        this.word = input.readInt();
    }

    @Override
    public String toString() {
        return rank + "\t" + word;
    }
}
